/**
 * creater:chuanpeng.zhu@dhc.com.cn
 * create time:2015/12/30
 * describe：本地存储服务
 */
APP
/**
 * 持久化存储
 */
  .factory('$localstorage', ['$window', function ($window) {
    return {
      set: function (key, value) {
        $window.localStorage[key] = value;
      },
      get: function (key, defaultValue) {
        return $window.localStorage[key] || defaultValue;
      },
      setObject: function (key, value) {
        $window.localStorage[key] = JSON.stringify(value);
      },
      getObject: function (key) {
        return JSON.parse($window.localStorage[key] || '{}');
      },
      setArray: function (key, value) {
        $window.localStorage[key] = JSON.stringify(value);
      },
      getArray: function (key) {
        return JSON.parse($window.localStorage[key] || '[]');
      }
    }
  }])

/**
 * describe：缓存服务
 */
  .service('CacheService', [function () {

    var cache = {};

    this.get = function (key) {
      return cache[key];
    };
    this.set = function (key, value) {
      return cache[key] = value;
    };
    this.pop = function (key) {
      var result = cache[key];
      cache[key] = '';
      return result;
    }
  }])
;
